package com.bestcem.xm.ticket.controller.convert.wechat;

import com.bestcem.xm.ticket.controller.vo.wechat.WechatUserInfoVO;
import com.bestcem.xm.ticket.dao.converter.CommonConverter;
import com.bestcem.xm.ticket.entity.mysql.TicketWechatDO;
import com.bestcem.xm.ticket.grpc.client.dto.wechat.WechatUserInfoDTO;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

import java.util.Objects;

/**
 * TicketWechat 实体相关转换类
 *
 * @author XiaoYunSong <ys.xiao@idiaoyan.com>
 * @version 通知提醒新增微信公众号
 * @date 2022/4/1 19:37
 */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class TicketWechatConvert {

    /**
     * TicketWechatDo 转 WechatUserInfoVO
     *
     * @param isDo TicketWechatDO实体
     * @return 对应的 WechatUserInfoVO
     * @author XiaoYunSong <ys.xiao@idiaoyan.com>
     * @date 2022/4/1 19:40
     */
    public static WechatUserInfoVO TicketWechatDOToVO(TicketWechatDO isDo) {
        if (Objects.isNull(isDo)) {
            return null;
        }
        WechatUserInfoVO isVo = new WechatUserInfoVO();
        isVo.setOpenId(isDo.getOpenId());
        isVo.setUnionId(isDo.getUnionId());
        isVo.setAvatar(isDo.getAvatar());
        isVo.setNickname(isDo.getNickname());
        isVo.setGender(isDo.getGender());
        isVo.setProvince(isDo.getProvince());
        isVo.setCity(isDo.getCity());
        isVo.setCountry(isDo.getCountry());
        isVo.setPrivilege(CommonConverter.stringToList(isDo.getPrivilege(), String.class));
        isVo.setCreateTime(isDo.getCreateTime());
        return isVo;
    }

    /**
     * WechatUserInfoDTO 转 TicketWechatDo
     *
     * @param isDto WechatUserInfoDTO实体
     * @return 对应的 TicketWechatDo
     * @author XiaoYunSong <ys.xiao@idiaoyan.com>
     * @date 2022/4/13 17:42
     */
    public static TicketWechatDO WechatUserInfoDTOToDO(WechatUserInfoDTO isDto) {
        if (Objects.isNull(isDto)) {
            return null;
        }
        TicketWechatDO isDo = new TicketWechatDO();
        isDo.setUnionId(isDto.getUnionId());
        isDo.setAvatar(isDto.getHeadImgUrl());
        isDo.setNickname(isDto.getNickname());
        isDo.setGender(isDto.getGender());
        isDo.setProvince(isDto.getProvince());
        isDo.setCity(isDto.getCity());
        isDo.setCountry(isDto.getCountry());
        isDo.setPrivilege(CommonConverter.listToString(isDto.getPrivilege()));
        return isDo;
    }
}
